package com.liang.blog.reception.controller;

import com.liang.blog.common.result.Result;
import com.liang.blog.model.BlogSessionList;
import com.liang.blog.reception.service.BlogSessionListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：YanWenLiang
 * @Date:2024-05-02-20:14
 */
@RestController
@RequestMapping("/session")
public class BlogSessionListController {

    @Autowired
    private BlogSessionListService blogSessionListService;

    /**
     * 创建会话对象，在用户点击其他用户头像开始私信时，创建该对象
     * @param fromUserId
     * @param toUserId
     * @return
     */
    @GetMapping("/add/{fromUserId}/{toUserId}")
    public Result createSessionList(@PathVariable Long fromUserId, @PathVariable Long toUserId){
        BlogSessionList sessionList = blogSessionListService.createSessionList(fromUserId, toUserId);
        return Result.ok(sessionList);
    }

    @GetMapping("/getHistory/{userId}")
    public Result getSessionListHistory(@PathVariable Long userId){
        List<BlogSessionList> sessionListHistory = blogSessionListService.getSessionListHistory(userId);
        return Result.ok(sessionListHistory);
    }

    @DeleteMapping("/del/{sessionListId}")
    public Result delSessionList(@PathVariable String sessionListId){
        blogSessionListService.removeById(sessionListId);
        return Result.ok();
    }


    @GetMapping("/edit/{sessionListId}/{remark}")
    public Result editSessionListRemark(@PathVariable String sessionListId,@PathVariable String remark){
        blogSessionListService.editSessionListRemark(sessionListId,remark);
        return Result.ok("修改成功");
    }
}
